package com.sohoometer;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.concurrent.CountDownLatch;

import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;

public class WebSocketDemo extends WebSocketServer{
	private HashMap<Integer, WebSocket> maps = new HashMap<Integer, WebSocket>();
	private static int count = 1;
	public WebSocketDemo(int port) throws UnknownHostException {
		super();
		InetSocketAddress inetSocketAddress = new InetSocketAddress(port);
		setAddress(inetSocketAddress);
	}

	@Override
	public void onOpen(WebSocket conn, ClientHandshake handshake) {
		conn.send("您好,欢迎来到我们的世界,哇哈哈");
		maps.put(count++, conn);
	}

	@Override
	public void onClose(WebSocket conn, int code, String reason, boolean remote) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onMessage(WebSocket conn, String message) {
		// TODO Auto-generated method stub
		conn.send(message+"-----"+"已经收到,等待处理");
	}

	@Override
	public void onError(WebSocket conn, Exception ex) {
		// TODO Auto-generated method stub
		
	}

	public HashMap<Integer, WebSocket> getMaps() {
		return maps;
	}

	public void setMaps(HashMap<Integer, WebSocket> maps) {
		this.maps = maps;
	}

}
